/**
 * 
 */
package ar.edu.utn.frsf.cidisi.ginet.generation.pnml2wscdl.managers;
import java.util.Map;

import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;

import ar.edu.utn.frsf.cidisi.ginet.formalization.FormalCBPLanguage;
import ar.edu.utn.frsf.cidisi.ginet.formalization.FormalizationPackage;

public class EMFModelLoad {
	public FormalCBPLanguage load() {
		// Initialize the model
		FormalizationPackage.eINSTANCE.eClass();
		String text = Platform
				.getPreferencesService()
				.getString(
						"ar.edu.utn.frsf.cidisi.ginet.generation.preferformalizationpage",
						"PATHG2W", "none", null);

		// Register the XMI resource factory for the .website extension
		Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
		Map<String, Object> m = reg.getExtensionToFactoryMap();
		m.put("formalization", new XMIResourceFactoryImpl());

		// Obtain a new resource set
		ResourceSet resSet = new ResourceSetImpl();

		// Get the resource
		Resource resource = resSet.getResource(URI.createFileURI(text),
		// URI.createURI("platform:/resource/ar.edu.utn.frsf.cidisi.ginet.test/model/upcolbpip-wscdl.formalization"),
				true);
		// Get the first model element and cast it to the right type, in my
		// example everything is hierarchical included in this first node
		FormalCBPLanguage myWeb = (FormalCBPLanguage) resource.getContents()
				.get(0);
		return myWeb;
	}
}
